/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.test;

import entities.TestRequireItem;
import java.util.ArrayList;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;

/**
 *
 * @author Admin
 */
public class AddTestModel implements TableModel {

    private String[] header;
    private ArrayList<TestRequireItem> rowsData;

    public AddTestModel(ArrayList<TestRequireItem> rowsData) {
        this.rowsData = rowsData;
    }

    public String[] getHeader() {
        return header;
    }

    public void setHeader(String[] header) {
        this.header = header;
    }
    

    @Override
    public int getRowCount() {
        if (rowsData != null) {
            return rowsData.size();
        } else {
            return 0;
        }
    }

    @Override
    public int getColumnCount() {
        return header.length;
    }

    @Override
    public String getColumnName(int columnIndex) {
        return header[columnIndex];
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        if (columnIndex==0) {
            return String.class;
        } else {
            return Integer.class;
        }
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        if (rowsData != null && rowsData.size() > rowIndex) {
            TestRequireItem t = rowsData.get(rowIndex);
            switch (columnIndex) {
                case 0:
                    return t.getStockDetail().getsName();
                case 1:
                    return t.getNumRequire();
            }
        }
        return null;
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void addTableModelListener(TableModelListener l) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void removeTableModelListener(TableModelListener l) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }
}
